/************************************************************************
**
** Authors:   Ulf Hermann <ulfonk_mennhar@gmx.de> (Alve), 
**            Marek Krejza <krejza@gmail.com> (Caligor)
**
** This file is part of the MMapper2 project. 
** Maintained by Marek Krejza <krejza@gmail.com>
**
** Copyright: See COPYING file that comes with this distribution
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file COPYING included in the packaging of
** this file.  
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
*************************************************************************/

#include "roomlocker.h"
#include "mapfrontend.h"

RoomLocker::RoomLocker(RoomRecipient * forward, MapFrontend * frontend, AbstractRoomFactory * in_factory, ParseEvent * compare) :
        recipient(forward),
        data(frontend),
        factory(in_factory),
comparator(compare) {}


RoomOutStream & RoomLocker::operator<<(const Room * room) {
    if (factory && comparator) {
        if (factory->compareWeakProps(room, comparator) != CR_DIFFERENT) {
            data->lockRoom(recipient, room->getId());
            recipient->receiveRoom(data, room);
        }
    } else {
        data->lockRoom(recipient, room->getId());
        recipient->receiveRoom(data, room);
    }
    return *this;
}
